
@include('Admin.public.head')
<style type="text/css">
    #my-popup2 {
        max-height: 420px;}
    #my-popup {max-height: 600px;}
</style>
<body>
@include('Admin.public.menu')
<div class=" admin-content" id="app">
    {{ csrf_field() }}
    <div class="daohang">
    </div>
    <!--添加模态框-->
    <div class="am-popup am-popup-inner" id="my-popup">
        <div class="am-popup-hd">
            <h4 class="am-popup-title">添加合伙人</h4>
            <span data-am-modal-close
                  class="am-close">&times;</span>
        </div>
        <div class="am-popup-bd">
            <form class="am-form">
                <div class="am-form-group am-cf">
                    <label class="sr-only" for="district1" >合伙人账号</label>
                    <div class="you">
                        <input  v-on:blur="upperCase()" class="am-form-field"  v-model="address.name" placeholder="请输入账号">
                    </div>
                </div>
				<span class="sr-only">系统姓名：</span><span style="color: red;">@{{ user_name }}</span>
				<div class="am-form-group am-cf" >
				    <label class="sr-only" for="district1" >合伙人姓名</label>
				    <div class="you">
						 <input class="am-form-field"  v-model="address.user_name" placeholder="请输入姓名">
				    </div>
				</div>
                <div class="am-text-center" style="margin-top: 20px ">
                    <a type="button" v-on:click="doApply()" class="am-btn am-btn-primary">添加</a>
                </div>
            </form>
        </div>
    </div>
	
	<div class="am-popup am-popup-inner" id="my-popup2">
	    <div class="am-popup-hd">
	        <h4 class="am-popup-title">手动分红</h4>
	        <span data-am-modal-close
	              class="am-close">&times;</span>
	    </div>
	    <div class="am-popup-bd">
	        <form class="am-form">
	            <div class="am-form-group am-cf">
	                <label class="sr-only" for="district1" >分红金额(/人)</label>
	                <div class="you">
	                    <input type="number"  v-on:blur="upperCase1()" class="am-form-field"  v-model="address.money" placeholder="请输入金额">
	                </div>
	            </div>
				<span class="am-form-group am-cf" style="font-weight: bold;">总分红人数：</span><span style="color: red;">@{{ user_name }}</span>
				<div class="am-form-group am-cf" >
				    <label class="sr-only" for="district1" >总分红金额</label>
				    <div class="you">
						 <input class="am-form-field"  v-model="address.user_name" disabled="disabled" placeholder="">
				    </div>
				</div>
				<div class="am-form-group am-cf">
				    <label class="sr-only" for="district1" >分红名称</label>
				    <div class="you">
				        <input  class="am-form-field"  v-model="address.name" placeholder="请输入名称">
				    </div>
				</div>
	            <div class="am-text-center" style="margin-top: 20px ">
	                <a type="button" v-on:click="doApply3()" class="am-btn am-btn-primary">提交</a>
	            </div>
	        </form>
	    </div>
	</div>
	
	<div class="am-popup am-popup-inner" id="my-popup1">
	    <div class="am-popup-hd">
	        <h4 class="am-popup-title">编辑</h4>
	        <span data-am-modal-close
	              class="am-close">&times;</span>
	    </div>
	    <div class="am-popup-bd">
	        <form class="am-form">
	            <div class="am-form-group am-cf">
	                <label class="sr-only" for="district1" >合伙人账号</label>
	                <div class="you">
	                    <input disabled="disabled"  v-on:blur="upperCase()" class="am-form-field"  v-model="address.name" placeholder="请输入账号">
	                </div>
	            </div>
				<span class="sr-only">系统姓名：</span><span style="color: red;">@{{ user_name }}</span>
				<div class="am-form-group am-cf" >
				    <label class="sr-only" for="district1" >合伙人姓名</label>
				    <div class="you">
						 <input  class="am-form-field"  v-model="address.user_name" placeholder="请输入姓名">
				    </div>
				</div>
				<div class="am-form-group am-cf" >
				    <label class="sr-only" for="district1" >状态</label>
				    <div class="you">
						 <label class="am-checkbox-inline">
						     <input type="radio" value="1" v-model="address.status" data-am-ucheck=""
						            class="am-ucheck-radio">
						     <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
						                 class="am-icon-checked"></i></span>成功
						 </label>
						 <label class="am-checkbox-inline">
						     <input type="radio" value="0" v-model="address.status" data-am-ucheck=""
						            class="am-ucheck-radio">
						     <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
						                 class="am-icon-checked"></i></span>失败
						 </label>
				    </div>
				</div>
				
	            <div class="am-text-center" style="margin-top: 20px ">
	                <a type="button" v-on:click="doApply1()" class="am-btn am-btn-primary">保存</a>
	            </div>
	        </form>
	    </div>
	</div>
	
	
	
	
    <div class="admin-biaogelist">
        <div class="listbiaoti am-cf">
            <ul class="am-icon-users"> 合伙人管理</ul>
            <dl>
                <button type="button" data-am-modal="{target: '#my-popup'}" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" >
                    添加合伙人
                </button>
            </dl>
            <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">代理商列表</a></dl>
            <!--这里打开的是新页面-->
        </div>
        <div class="am-btn-toolbars am-btn-toolbar am-kg am-cf">
            <ul>
                <li>
                    <template>
                        <el-select v-model="keyword.status" placeholder="代理状态">
                            <el-option
                                    size="medium"
                                    v-for="item in ordertype"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </li>

                <li>
                    <el-input v-model="keyword.keyword" class="keywords" placeholder="关键词搜索"></el-input>
                </li>
                <li>
                    <el-button type="primary" v-on:click="changeClick()">搜索</el-button>
                </li>
                <li> <el-button type="danger" v-on:click="resetOrder()">重置</el-button></li>
				<li> <el-button type="success" data-am-modal="{target: '#my-popup2'}" >分红</el-button></li>
            </ul>
        </div>


        <form class="am-form am-g">
            <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                <tr class="am-success">
                    <th class="table-id" style="width: 120px;">姓名</th>
                    <th class="table-title">账号</th>
                    <th class="table-title">状态</th>
					<th class="table-title">操作人</th>
                    <th class="table-type">添加时间</th>
                    <th width="130px" class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="val,index in ApplyList">
                    <td>@{{ val.user_name }}</td>
                    <td>@{{ val.name }}</td>
                    <td v-show="val.status == 1">成功 </td>
                    <td v-show="val.status == 0">失败 </td>
					<td>@{{ val.verifier }}</td>
                    <td>@{{ val.updated_at }}</td>
                    <td style="width:250px;">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <a style="background-color: #4db14d;border-color: #4db14d;" class="am-btn am-btn-danger am-radius"  data-am-modal="{target: '#my-popup1'}" v-on:click="doEditor(val)" title="编辑" >编辑</a>
                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <!--分页-->
            <ul class="am-pagination am-fr">
                <div class="block">
                    <el-pagination
                            background
                            :page-size="PagesData.per_page"
                            :current-page = "PagesData.current_page"
                            layout="total , prev, pager, next"
                            :total="PagesData.total"
                            @prev-click="changeClick"
                            @next-click="changeClick"
                            @current-change="changeClick">
                    </el-pagination>
                </div>
            </ul>

        </form>
        <script src="{{ URL::asset('js/address/distpicker.data.js') }}"></script>
        <script src="{{ URL::asset('js/address/distpicker.js') }}"></script>
        <script>
            var app = new Vue({
                el:"#app",
                data: {
					user_name:'',
                    ApplyList : [], //代理商列表
                    PagesData:[],//分页
                    options: [
						/* {
                        value: '0',
                        label: '省代理'
                    }, */
					{
                        value: '1',
                        label: '市代理'
                    },{
                        value: '2',
                        label: '县代理'
                    }],
                    ordertype: [{
                        value: '0',
                        label: '待审核'
                    }, {
                        value: '1',
                        label: '通过'
                    },{
                        value: '2',
                        label: '拒绝'
                    },{
                        value: '3',
                        label: '回收'
                    }],
                    keyword:{ //关键字搜索
                        type:'',
                        status:'',
                        keyword:'',
                        // created_at:'',
                    },
                    address: {
                        'id':'',
                        'phone':'',
                        'type':'0',
                        'province':'北京市',
                        'city':'',
                        'district':'',
                        'districts':'',
                        'status':'',
						'partner':'',
						'user_name':'',
						'name':'',
						'money':''
                    },
                },
                //事件
                methods: {
					obtain:function (val) {
					    var query = window.location.search.substring(1);
					    var vars = query.split("&");
					    for (var i=0;i<vars.length;i++) {
					        var pair = vars[i].split("=");
					        if(pair[0] == val){
					            return pair[1];
					        }
					    }
					},
					par:function (id) {
						window.location.href="/admin/members/agentList?id="+id;
					},
                    //选择当前页
                    changeClick:function(e){
      //                   var rico = this
						// var id = this.obtain('id');
                        $.get("/admin/system/shareholders",{'_token':'{{csrf_token()}}',class:'select',page:e,keyword:app.keyword},function (res) {
                            if(res.code){
                                app.ApplyList = res.data.data
                                app.PagesData = res.data
                            } else {
                                layer.msg(res.data);
                            }
                        });
                    },

                    initialize:function () {
      //                   var rico = this
      //                   //代理商列表
						// var id = this.obtain('id');
                        $.get("/admin/system/shareholders",{'_token':'{{csrf_token()}}',class:'select'},function (res) {
                            if(res.code){
                                app.ApplyList = res.data.data
                                app.PagesData = res.data
                            } else {
                                layer.msg(res.data);
                            }
                        });

                    },
					upperCase:function () {
					    if(!(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(app.address.name))){
					        layer.msg('请输入正确账号');
					        return false;
					    }
					    $.post("/admin/members/partnerList", {'_token': '{{csrf_token()}}',class:'find_member',name:app.address.name}, function (res) {
					        if (res.code == 1 ) {
					             app.user_name = res.data.user_name
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
					upperCase1:function () {
					    $.post("/admin/system/shareholders", {'_token': '{{csrf_token()}}',class:'calculation',money:app.address.money}, function (res) {
					        if (res.code == 1 ) {
								app.user_name = res.count
								app.address.user_name = res.total
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
                    //添加区县
                    doDistrict:function () {
                        app.address.districts = (app.address.districts == '')?app.address.district:app.address.districts+','+app.address.district
                    },
                    //代理申请
                    doApply:function(){
						var id = this.obtain('id');
                        var rico = this
                        if(!(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(app.address.name))){
                            layer.msg('请输入正确的电话号码');
                            return false;
                        }
                        $.post("/admin/system/shareholders", {'_token': '{{csrf_token()}}','class':'add ',name:app.address.name,user_name:app.address.user_name}, function (res) {
                            if (res.code) {
								layer.msg(res.data);
                                window.location.href="/admin/system/setShareholders";
                            } else {
                                layer.msg(res.data);
                            }
                        });
                    },
					doApply3:function(){
					    $.post("/admin/system/shareholders", {'_token': '{{csrf_token()}}','class':'switch',name:app.address.name,money:app.address.money,number:app.user_name,total_money:app.address.user_name}, function (res) {
					        if (res.code) {
								layer.msg(res.data);
					            window.location.href="/admin/system/setShareholders";
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
					doApply1:function(){
						var id = this.obtain('id');
					    $.post("/admin/system/shareholders", {'_token': '{{csrf_token()}}',class:'edit',id:app.address.id,status:app.address.status,name:app.address.name,user_name:app.address.user_name}, function (res) {
					        if (res.code) {
					            layer.msg(res.data);
								window.location.href="/admin/system/setShareholders";
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
					del:function (id,index) {
					    $.post("/admin/classify/goods",{'_token':'{{csrf_token()}}',class:'delete',id:id},function (res) {
					        if(res.code){
					            app.shopList.splice(index,1)
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
                    //编辑代理
                    doEditor:function(data){
                        app.address.id = data.id;
						app.address.partner = data.partner;
                        app.address.status = data.status;
                        app.address.phone = data.phone;
						app.address.name = data.name;
						app.address.user_name = data.user_name;
                    },
                    //审核通过
                    approve:function (id) {
                        var that = this;
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'edit',id:id},function (res) {
                            if(res.code){
                                layer.msg(res.data,{icon: 6},function () {
                                    // location.reload();
                                    that.initialize();
                                },500);
                            }
                        });
                    },
                    //拒绝
                    reject:function(id) {
                        var that = this;
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'reEdit',id:id},function (res) {
                            if(res.code){
                                layer.msg(res.data,{icon: 6},function () {
                                    // location.reload();
                                    that.initialize();
                                },500);
                            }
                        });
                    },
                    //开通
                    back:function(id) {
                        var that = this;
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'back',id:id},function (res) {
                            if(res.code){
                                layer.msg(res.data,{icon: 6},function () {
                                    // location.reload();
                                    that.initialize();
                                },500);
                            }
                        });
                    },

                    //重置
                    resetOrder:function(){

                        location.reload();
                    }
                },

                //自动执行
                mounted: function () {
                    this.initialize();//分公司
                },
            })
        </script>
@include('Admin.public.foot')